[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
_chmod() Change Access Mode of File
#include <io.h>
int _chmod(filename,func[,attrib]);
const char *filename; Name of existing file
int func; Operation to perform
int attrib; Attribute constant
_chmod() can either retrieve or set the attributes of the file
specified by 'filename'. If 'func' is set to 0, _chmod() gets the
current attributes. If 'func' is set to 1, the attribute is set to
'attrib', which can be one of the following constants:
FA_RDONLY Read only
FA_HIDDEN Hidden file
FA_SYSTEM System file
Returns: The file attribute word, if successful. On failure,
-1 is returned and 'errno' (defined in <errno.h>) is
set to either ENOENT (file not found) or EACCES
(permission denied).
Portability: MS-DOS only.
-------------------------------- Example ---------------------------------
The following statements make the file "MYDATA.DAT" read only.
#include <stdio.h> /* for printf */
#include <io.h> /* for _chmod */
#include <dos.h> /* for io.h */
#include <errno.h> /* for errno and ENOENT */
main()
{
if (_chmod("mydata.dat",1,FA_RDONLY) == -1) {
if (errno == ENOENT)
printf("couldn't find mydata.dat\n");
else
printf("couldn't set read-only attribute\n");
}
else
printf("mydata.dat set to read-only\n");
}
See Also:
access()
chmod()
open()
unlink()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson